import type { AppRouteRecord } from "@/types/router";
import { RoutesAlias } from "../routesAlias";
import { WMS_PERMISSIONS } from "@/utils/sys/permission";

/**
 * WMS仓库管理系统路由配置
 *
 * 集成完整的权限控制系统，支持：
 * - 基于角色的访问控制
 * - 基于权限标识的精细化权限控制
 * - WMS专用权限列表（authList）
 * - 菜单图标和国际化支持
 */
export const wmsRoutes: AppRouteRecord[] = [
  {
    path: "/wms",
    name: "WMS",
    component: RoutesAlias.Layout,
    meta: {
      title: "WMS仓库管理",
      icon: "&#xe723;", // warehouse icon
      isHideTab: false,
      order: 1,
      roles: ["admin", "wms_admin", "wms_user"], // 角色权限控制
    },
    children: [
      // 基础数据管理
      {
        path: "/wms/basic",
        name: "WmsBasic",
        component: RoutesAlias.Layout,
        meta: {
          title: "基础数据",
          icon: "&#xe860;", // setting icon
          order: 1,
        },
        children: [
          {
            path: "/wms/basic/warehouse",
            name: "WmsWarehouse",
            component: "/wms/basic/warehouse/index",
            meta: {
              title: "仓库管理",
              icon: "&#xe723;", // building icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.WAREHOUSE.LIST], // 权限标识
              authList: [
                {
                  title: "查看仓库列表",
                  authMark: WMS_PERMISSIONS.WAREHOUSE.LIST,
                },
                { title: "新增仓库", authMark: WMS_PERMISSIONS.WAREHOUSE.ADD },
                {
                  title: "编辑仓库",
                  authMark: WMS_PERMISSIONS.WAREHOUSE.EDIT,
                },
                {
                  title: "删除仓库",
                  authMark: WMS_PERMISSIONS.WAREHOUSE.DELETE,
                },
                {
                  title: "导出仓库",
                  authMark: WMS_PERMISSIONS.WAREHOUSE.EXPORT,
                },
              ],
            },
          },
          {
            path: "/wms/basic/area",
            name: "WmsArea",
            component: "/wms/basic/area/index",
            meta: {
              title: "库区管理",
              icon: "&#xe81a;", // grid icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.AREA.LIST],
              authList: [
                { title: "查看库区列表", authMark: WMS_PERMISSIONS.AREA.LIST },
                { title: "新增库区", authMark: WMS_PERMISSIONS.AREA.ADD },
                { title: "编辑库区", authMark: WMS_PERMISSIONS.AREA.EDIT },
                { title: "删除库区", authMark: WMS_PERMISSIONS.AREA.DELETE },
                { title: "导出库区", authMark: WMS_PERMISSIONS.AREA.EXPORT },
              ],
            },
          },
          {
            path: "/wms/basic/merchant",
            name: "WmsMerchant",
            component: "/wms/basic/merchant/index",
            meta: {
              title: "商户管理",
              icon: "&#xe7ac;", // user icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.MERCHANT.LIST],
              authList: [
                {
                  title: "查看商户列表",
                  authMark: WMS_PERMISSIONS.MERCHANT.LIST,
                },
                { title: "新增商户", authMark: WMS_PERMISSIONS.MERCHANT.ADD },
                { title: "编辑商户", authMark: WMS_PERMISSIONS.MERCHANT.EDIT },
                {
                  title: "删除商户",
                  authMark: WMS_PERMISSIONS.MERCHANT.DELETE,
                },
                {
                  title: "导出商户",
                  authMark: WMS_PERMISSIONS.MERCHANT.EXPORT,
                },
              ],
            },
          },
          {
            path: "/wms/basic/item",
            name: "WmsItem",
            component: "/wms/basic/item/index",
            meta: {
              title: "商品管理",
              icon: "&#xe7c4;", // box icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.ITEM.LIST],
              authList: [
                { title: "查看商品列表", authMark: WMS_PERMISSIONS.ITEM.LIST },
                { title: "新增商品", authMark: WMS_PERMISSIONS.ITEM.ADD },
                { title: "编辑商品", authMark: WMS_PERMISSIONS.ITEM.EDIT },
                { title: "删除商品", authMark: WMS_PERMISSIONS.ITEM.DELETE },
                { title: "SKU管理", authMark: WMS_PERMISSIONS.ITEM.SKU },
                { title: "导入商品", authMark: WMS_PERMISSIONS.ITEM.IMPORT },
                { title: "导出商品", authMark: WMS_PERMISSIONS.ITEM.EXPORT },
              ],
            },
          },
        ],
      },

      // 库存管理
      {
        path: "/wms/inventory",
        name: "WmsInventory",
        component: "/wms/inventory/index",
        meta: {
          title: "库存管理",
          icon: "&#xe74c;", // goods icon
          keepAlive: true,
          permissions: [WMS_PERMISSIONS.INVENTORY.LIST],
          authList: [
            {
              title: "查看库存列表",
              authMark: WMS_PERMISSIONS.INVENTORY.LIST,
            },
            { title: "库存调整", authMark: WMS_PERMISSIONS.INVENTORY.ADJUST },
            {
              title: "库存分配",
              authMark: WMS_PERMISSIONS.INVENTORY.ALLOCATE,
            },
            { title: "库存历史", authMark: WMS_PERMISSIONS.INVENTORY.HISTORY },
            { title: "导出库存", authMark: WMS_PERMISSIONS.INVENTORY.EXPORT },
          ],
        },
      },

      // 订单管理
      {
        path: "/wms/order",
        name: "WmsOrder",
        component: RoutesAlias.Layout,
        meta: {
          title: "订单管理",
          icon: "&#xe738;", // document icon
          order: 3,
        },
        children: [
          {
            path: "/wms/order/receipt",
            name: "WmsReceiptOrder",
            component: "/wms/order/receipt/index",
            meta: {
              title: "入库单管理",
              icon: "&#xe717;", // download icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.RECEIPT.LIST],
              authList: [
                {
                  title: "入库单完整权限",
                  authMark: WMS_PERMISSIONS.RECEIPT.ALL,
                },
                {
                  title: "查看入库单列表",
                  authMark: WMS_PERMISSIONS.RECEIPT.LIST,
                },
                { title: "新增入库单", authMark: WMS_PERMISSIONS.RECEIPT.ADD },
                {
                  title: "编辑入库单",
                  authMark: WMS_PERMISSIONS.RECEIPT.EDIT,
                },
                {
                  title: "删除入库单",
                  authMark: WMS_PERMISSIONS.RECEIPT.DELETE,
                },
                {
                  title: "确认入库",
                  authMark: WMS_PERMISSIONS.RECEIPT.CONFIRM,
                },
                {
                  title: "取消入库单",
                  authMark: WMS_PERMISSIONS.RECEIPT.CANCEL,
                },
                {
                  title: "导出入库单",
                  authMark: WMS_PERMISSIONS.RECEIPT.EXPORT,
                },
              ],
            },
          },
          {
            path: "/wms/order/shipment",
            name: "WmsShipmentOrder",
            component: "/wms/order/shipment/index",
            meta: {
              title: "出库单管理",
              icon: "&#xe718;", // upload icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.SHIPMENT.LIST],
              authList: [
                {
                  title: "出库单完整权限",
                  authMark: WMS_PERMISSIONS.SHIPMENT.ALL,
                },
                {
                  title: "查看出库单列表",
                  authMark: WMS_PERMISSIONS.SHIPMENT.LIST,
                },
                {
                  title: "新增出库单",
                  authMark: WMS_PERMISSIONS.SHIPMENT.ADD,
                },
                {
                  title: "编辑出库单",
                  authMark: WMS_PERMISSIONS.SHIPMENT.EDIT,
                },
                {
                  title: "删除出库单",
                  authMark: WMS_PERMISSIONS.SHIPMENT.DELETE,
                },
                {
                  title: "确认出库",
                  authMark: WMS_PERMISSIONS.SHIPMENT.CONFIRM,
                },
                {
                  title: "取消出库单",
                  authMark: WMS_PERMISSIONS.SHIPMENT.CANCEL,
                },
                {
                  title: "导出出库单",
                  authMark: WMS_PERMISSIONS.SHIPMENT.EXPORT,
                },
              ],
            },
          },
          {
            path: "/wms/order/movement",
            name: "WmsMovementOrder",
            component: "/wms/order/movement/index",
            meta: {
              title: "移库单管理",
              icon: "&#xe6a5;", // switch icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.MOVEMENT.LIST],
              authList: [
                {
                  title: "查看移库单列表",
                  authMark: WMS_PERMISSIONS.MOVEMENT.LIST,
                },
                {
                  title: "新增移库单",
                  authMark: WMS_PERMISSIONS.MOVEMENT.ADD,
                },
                {
                  title: "编辑移库单",
                  authMark: WMS_PERMISSIONS.MOVEMENT.EDIT,
                },
                {
                  title: "删除移库单",
                  authMark: WMS_PERMISSIONS.MOVEMENT.DELETE,
                },
                {
                  title: "确认移库",
                  authMark: WMS_PERMISSIONS.MOVEMENT.CONFIRM,
                },
                {
                  title: "导出移库单",
                  authMark: WMS_PERMISSIONS.MOVEMENT.EXPORT,
                },
              ],
            },
          },
          {
            path: "/wms/order/check",
            name: "WmsCheckOrder",
            component: "/wms/order/check/index",
            meta: {
              title: "盘点单管理",
              icon: "&#xe73a;", // list icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.CHECK.LIST],
              authList: [
                {
                  title: "查看盘点单列表",
                  authMark: WMS_PERMISSIONS.CHECK.LIST,
                },
                { title: "新增盘点单", authMark: WMS_PERMISSIONS.CHECK.ADD },
                { title: "编辑盘点单", authMark: WMS_PERMISSIONS.CHECK.EDIT },
                {
                  title: "删除盘点单",
                  authMark: WMS_PERMISSIONS.CHECK.DELETE,
                },
                { title: "确认盘点", authMark: WMS_PERMISSIONS.CHECK.CONFIRM },
                {
                  title: "导出盘点单",
                  authMark: WMS_PERMISSIONS.CHECK.EXPORT,
                },
              ],
            },
          },
        ],
      },

      // 报表统计
      {
        path: "/wms/report",
        name: "WmsReport",
        component: RoutesAlias.Layout,
        meta: {
          title: "报表统计",
          icon: "&#xe7a2;", // data analysis icon
          order: 4,
        },
        children: [
          {
            path: "/wms/report/inventory",
            name: "WmsInventoryReport",
            component: "/wms/report/inventory/index",
            meta: {
              title: "库存报表",
              icon: "&#xe7a1;", // pie chart icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.REPORT.INVENTORY],
              authList: [
                {
                  title: "查看库存报表",
                  authMark: WMS_PERMISSIONS.REPORT.INVENTORY,
                },
              ],
            },
          },
          {
            path: "/wms/report/order",
            name: "WmsOrderReport",
            component: "/wms/report/order/index",
            meta: {
              title: "订单报表",
              icon: "&#xe7a0;", // trend charts icon
              keepAlive: true,
              permissions: [WMS_PERMISSIONS.REPORT.ORDER],
              authList: [
                {
                  title: "查看订单报表",
                  authMark: WMS_PERMISSIONS.REPORT.ORDER,
                },
              ],
            },
          },
        ],
      },
    ],
  },
];
